/*
 * @describe: ***
 * @version: 1.0
 * @Author: yanghm
 * @Date: 2023-04-06 16:16:10
 * @LastEditors: yanghm
 * @LastEditTime: 2023-04-14 08:47:51
 */
import axios from 'axios'
// import store from '@/store/index.js'
// import router from '@/router/index.js'
import { Message } from 'element-ui'

let baseUrl = '/api'
let apiCommon = '/defectCenter'
// 创建axios实例
const service = axios.create({
  timeout: 30000, // 请求超时时间
  cache: true,
  headers: {
    common: {
      'X-Requested-With': 'XMLHttpRequest'
    }
  }
})
// http request 拦截器
service.interceptors.request.use(
  config => {
    if (localStorage.token) {
      config.headers.Authorization = localStorage.token
    }
    return config
  },
  err => {
    return Promise.reject(err)
  })
// http response 拦截器
service.interceptors.response.use(response => {
  return {
    ...response.data,
    $responseBody: response
  }
}, error => {
    console.log('err', error)
    Message.error(error.message)
    return Promise.reject(error)
  })
// get请求
const get = (url, params) => service.get(baseUrl + url, { params })
// post请求
const post = (url, params, config) => service.post(baseUrl + url, params, config)
// 获取获取字典数据项
const getDictData = (data) => { return post(apiCommon + '/dict/dictSearch', data) }
// 登录
const getToken = (data) => { return post(apiCommon + '/auth/session/getToken', data) }
// 登出
const logout = (data) => { return get(apiCommon + '/', data) }
// 用户信息
const getUserInfo = (data) => { return get(apiCommon + '/', data) }
// 组织机构树-单位
const getOrgTree = (data) => { return post(apiCommon + '/org/orgTree', data) }
// 组织机构树-运维单位
const getOperationOrgTree = (data) => { return post(apiCommon + '/org/operationOrgTree', data) }
// 获取列表
const getHomeList = (data) => post(apiCommon + '/defect/list', data)

// 获取列表
const exportForm = (data) => post(apiCommon + '/defect/exportList', data, { responseType: 'blob' })
export {
  get,
  post,
  getDictData,
  getToken,
  logout,
  getUserInfo,
  getOrgTree,
  getOperationOrgTree,
  getHomeList,
  exportForm
}
